package com.skivingcloud.admin.security;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * 免密登录时使用，常用于集成第三方单点登录
 * @author hushouquan
 */
public class NoPasswordToken extends AbstractAuthenticationToken{
    
    private final Object principal;
    
    public NoPasswordToken(Object principal) {
        super(null);
        this.principal = principal;
        super.setAuthenticated(false);
    }
    
    public NoPasswordToken(Object principal, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        super.setAuthenticated(true);
    }
    
    @Override
    public Object getCredentials(){
        return null;
    }
    
    @Override
    public Object getPrincipal(){
        return principal;
    }
}
